<!--
 * @Author: your name
 * @Date: 2021-07-27 17:21:05
 * @LastEditTime: 2021-07-27 17:26:14
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>队列</title>
</head>
<body>
  <script>
    function Queue() {
      this.items = []

      // 加入队列
      Queue.prototype.enqueue = function(element) {
        this.items.push(element)
      }

      // 从队列中删除前端元素
      Queue.prototype.dequeue = function() {
        return this.items.shift()
      }

      // 查看前端的元素
      Queue.prototype.front = function() {
        return this.items[0]
      }

      // 查看队列是否为空
      Queue.prototype.isEmpty = function() {
        return this.items.length === 0
      }

      // 查看队列中元素的个数
      Queue.prototype.size = function() {
        return this.items.length
      }

      // toString方法
      Queue.prototype.toString = function() {
        var resultString = ''
        for(var i = 0;i<items.length;i++) {
          resultString += this.items[i] + ' '
        }
        return resultString
      }
    }
  </script>
</body>
</html>